2020-2021 Sunseeker Telemetry and Lighting System
usci_a_uart_ex2_addressBitMultiprocessorTX.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 #include "driverlib.h"
33 
34 //******************************************************************************
61 //******************************************************************************
62 #define BAUD_RATE 9600
63 #define TRANSMIT_DATA_COUNT 0x02
64 #define USCI_A_UART_MULTIPROCESSOR_MODE_ADDRESS 0xAA
65 
66 uint8_t receivedData = 0x00, transmitData = 0x00;
69 
70 void main (void)
71 {
72  //Stop WDT
73  WDT_A_hold(WDT_A_BASE);
74 
75  //P3.4,5 = USCI_A0 TXD/RXD
76  GPIO_setAsPeripheralModuleFunctionInputPin(
77  GPIO_PORT_P3,
78  GPIO_PIN4 + GPIO_PIN5
79  );
80 
81  //Baudrate = 9600, clock freq = 1.048MHz
82  //UCBRx = 109, UCBRFx = 0, UCBRSx = 2, UCOS16 = 0
83  USCI_A_UART_initParam param = {0};
84  param.selectClockSource = USCI_A_UART_CLOCKSOURCE_ACLK;
85  param.clockPrescalar = 109;
86  param.firstModReg = 0;
87  param.secondModReg = 2;
88  param.parity = USCI_A_UART_NO_PARITY;
89  param.msborLsbFirst = USCI_A_UART_MSB_FIRST;
90  param.numberofStopBits = USCI_A_UART_ONE_STOP_BIT;
91  param.uartMode = USCI_A_UART_ADDRESS_BIT_MULTI_PROCESSOR_MODE;
92  param.overSampling = USCI_A_UART_LOW_FREQUENCY_BAUDRATE_GENERATION;
93  if (STATUS_FAIL == USCI_A_UART_init(USCI_A0_BASE, &param)){
94  return;
95  }
96 
97  //Enable UART module for operation
98  USCI_A_UART_enable(USCI_A0_BASE);
99 
100  //Send Address Frame
101  USCI_A_UART_transmitAddress(USCI_A0_BASE, transmitAddress);
102 
103  //Enable Receive Interrupt
104  USCI_A_UART_clearInterrupt(USCI_A0_BASE,
105  USCI_A_UART_RECEIVE_INTERRUPT
106  );
107  USCI_A_UART_enableInterrupt(USCI_A0_BASE,
108  USCI_A_UART_RECEIVE_INTERRUPT
109  );
110 
111  //Enter LPM3, interrupts enabled
112  __bis_SR_register(LPM3_bits + GIE);
113  __no_operation();
114 }
115 
116 //******************************************************************************
117 //
118 //This is the USCI_A0 interrupt vector service routine.
119 //
120 //******************************************************************************
121 #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
122 #pragma vector=USCI_A0_VECTOR
123 __interrupt
124 #elif defined(__GNUC__)
125 __attribute__((interrupt(USCI_A0_VECTOR)))
126 #endif
127 void USCI_A0_ISR (void)
128 {
129  switch (__even_in_range(UCA0IV,4)){
130  //Vector 2 - RXIFG
131  case 2:
132 
133  //Receive the data
134  receivedData = USCI_A_UART_receiveData(USCI_A0_BASE);
135 
136  if (transmitDataCount){
137  //Transmit data
138  USCI_A_UART_transmitData(USCI_A0_BASE,
139  transmitData++);
141  } else {
142  //Transmit Address
143  USCI_A_UART_transmitAddress(USCI_A0_BASE,
146  }
147 
148 
149  break;
150  default: break;
151  }
152 }
153 
MPU_initThreeSegmentsParam param
__no_operation()
#define STATUS_FAIL
Definition: hw_memmap.h:23
#define USCI_A_UART_MULTIPROCESSOR_MODE_ADDRESS